package com.blockchain.securewallet.utils;

import android.util.Log;

import com.subgraph.orchid.encoders.Hex;

import java.util.Arrays;
import java.util.List;

public class LogUtil {
    private static final String TAG = "Wallet.Log";

    public static void showInNumbers(byte[] bytes,String label) {
        if (bytes==null)
            return;
        StringBuilder builder = new StringBuilder();
        for (byte b:bytes) {
            builder.append(b+" ");
        }
        Log.i(TAG,(label==null?"":label)+" numbers:["+builder.toString()+"]");
    }

    public static void showInHex(byte[] bytes,String label) {
        if (bytes==null)
            return;
        byte[] encode = Hex.encode(bytes);
        StringBuilder builder = new StringBuilder();
        int i = 0;
        for (byte b:encode) {
            if(i%2==0 && i!=0) {
                builder.append(" ");
            }
            builder.append((char)b);
            ++i;
        }
        Log.i(TAG,(label==null?"":label)+" hex:["+builder.toString()+"]");
    }

    public static void showInChar(byte[] bytes,String label) {
        if (bytes==null)
            return;
        StringBuilder builder = new StringBuilder();
        for (byte b:bytes) {
            builder.append((char)b+" ");
        }
        Log.i(TAG,(label==null?"":label)+" char:["+builder.toString()+"]");
    }

    public static void showListOfString(List<String> strs,String label){
        if (strs==null)
            return;
        StringBuilder builder = new StringBuilder();
        for (String str:strs) {
            builder.append(str+" ");
        }
        Log.i(TAG,(label==null?"":label)+" List:["+builder.toString()+"]");
    }

    public static void showArrayOfString(String[] strs, String label){
        if (strs==null)
            return;
        StringBuilder builder = new StringBuilder();
        for (String str:strs) {
            builder.append(str+" ");
        }
        Log.i(TAG,(label==null?"":label)+" Array:["+builder.toString()+"]");
    }

}
